﻿#ifndef __SS_SHELL_H__
#define __SS_SHELL_H__
#include <cstdlib>
#include <cstdio>
#include <string>

namespace StarSeeker
{

	inline bool ShellCommand(const char *str)
	{
		int ret = system(str);
		return ret == 0;
	}

	inline std::string PipeCommand(const char *str)
	{
		char path[1024] = {0};
		std::string output;

		// 执行命令并读取输出
#ifdef _WIN32
		FILE *fp = ::_popen(str, "r");
#else
		FILE *fp = ::popen(str, "r");
#endif
		if (fp == NULL)
		{
			return output;
		}
		while (::fgets(path, sizeof(path), fp) != NULL)
		{
			output += path;
		}

		// 关闭管道并获取命令的返回状态
#ifdef _WIN32
		int status = ::_pclose(fp);
#else
		int status = ::pclose(fp);
#endif
		return output;
	}

}

#endif
